<?php

// import database connection variables and connectToMysql method
require_once __DIR__ . '/db_config.php';

$mysqli = connectToMysql();

$query = "select * from Company";

if ($result = $mysqli->query($query)) {

    /* fetch object array */
    while ($row = $result->fetch_assoc()) {
        $output[] =  array_map('utf8_encode', $row);
    }

    /* free result set */
    $result->close();
}  else {
    print mysqli_error($mysqli);
}

/* close connection */
$mysqli->close();

// this will print the output in json

$finalResult = json_encode($output, JSON_NUMERIC_CHECK);

$finalResult = str_replace('"latitude":""', '"latitude":null', $finalResult);
$finalResult = str_replace('"longitude":""', '"longitude":null', $finalResult);
$finalResult = str_replace('"averageRating":""', '"averageRating":null', $finalResult);

echo $finalResult;
?>